<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=0" name="viewport">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>一朵 - 完善信息</title>
  <!-- swiper-2.7css -->
    <link rel="stylesheet" href="__STATIC__/index/js/swiper/idangerous.swiper.css">
  <!-- swiper-2.7js -->
    <script src="__STATIC__/index/js/swiper/idangerous.swiper.min.js"></script>
  <!-- jquery-3.2.1引用 -->
    <script src="__STATIC__/index/js/global/jquery-3.2.1.min.js"></script>
  <!-- 阿里巴巴矢量图库 -->
    <link rel="stylesheet" href="http://at.alicdn.com/t/font_561814_yo33l6f1qxhl4n29.css">
  <!-- 公共头部 脚部 -->
    <link rel="stylesheet" href="__STATIC__/index/css/global/global.css">
  <!-- 超过1200屏幕 -->
    <link rel="stylesheet" media="screen and (min-width: 1200px)" href="__STATIC__/index/css/information/information1200.css" />
  <!-- 1080-1200 -->
    <link rel="stylesheet" media="screen  and (min-width: 1080px) and (max-width: 1199px) " href="__STATIC__/index/css/information/information1080.css"
    />
  <!-- 960-1080 -->
    <link rel="stylesheet" media="screen  and (min-width: 960px) and (max-width: 1079px) " href="__STATIC__/index/css/information/information960.css"
    />
  <!-- 768-959 -->
    <link rel="stylesheet" media="screen  and (min-width: 768px) and (max-width: 959px) " href="__STATIC__/index/css/information/information768.css"
    />
  <!-- 568-767 -->
    <link rel="stylesheet" media="screen  and (min-width: 568px) and (max-width: 767px) " href="__STATIC__/index/css/information/information568.css"
    />
  <!-- 375-567 -->
    <link rel="stylesheet" media="screen  and (min-width: 375px) and (max-width: 567px) " href="__STATIC__/index/css/information/information375.css"
    />
  <!-- 小于375-->
    <link rel="stylesheet" media="screen  and (max-width: 374px) " href="__STATIC__/index/css/information/information320.css" />
  <!--一引入layer-->
    <script src="__STATIC__/layer/layer.js"></script>
</head>

<body>
    <form action="{:url('User/m_edit_member_info')}" method="post" id="form1">
    <div class="M">
        <div class="m-header">
            <div>
                <span onclick="go_back();">
                    <span class="iconfont icon-xiangzuo" ></span>
                    返回
                </span>
                <span>完善信息</span>
                <span>
                    {if condition="!empty($realname)"}
                        <a href="{:url('User/index')}" class="my" >
                            {$realname}
                        </a>
                    {else /}
                        <a href="{:url('Login/loginin')}">登录</a>
                        <a href="{:url('Login/register')}">注册</a>
                    {/if}
                    <a href="{:url('MyCart/my_cart')}" class="car">
                        <span class="iconfont icon-gouwuche"></span>
                        <span>{$cart_num}</span>
                    </a>
                </span>
            </div>

        </div>
        <div class="m-img">
            <div>
                <span>头像</span>
                <label for="image_file1">
                    <img class="image_file1" src="{if condition='empty($user.logo)'}__STATIC__/index/touxiang.png{else /}{$user.logo}{/if}" />
                    <span>修改个人头像</span>
                </label>
                <input type="hidden" class="image_file1" name="image_file"/>
                <input type="file" id="image_file1" style="display:none;" onchange="uploadImg(this);" />
            </div>
        </div>
        <div class="m-name">
            <div>
                <span>昵称</span>
                <input type="text" placeholder="请输入昵称" name="realname" value="{$user.realname}" onkeyup="set_realname(this)">
            </div>
        </div>
        <div class="m-number">
            <div>
                <span>手机</span>
                <span>
                    {$user.mobile}
                </span>
                <span>
                    <span>
                        <a href="{:url('User/edit_mobile')}">修改</a>
                    </span>
                    <span>(仅自己可见)</span>
                </span>
            </div>
        </div>
        <div class="m-gender">
            <div>
                <span>性别</span>
                <span>
                    <select name="sex" id="sex" >
                        <option value="">点击选择</option>
                        <option value="1" {if condition="$user.sex eq 1"} selected {/if}>男</option>
                        <option value="0" {if condition="$user.sex eq 0"} selected {/if}>女</option>
                    </select>
                </span>
            </div>
        </div>
        <div class="m-birthday">
            <div>
                <span>生日</span>
                <span>
                    <input type="date" name="birthday" id="birthday" value="{$user.birthday_year}-{$user.birthday_month}-{$user.birthday_day}">
                </span>
            </div>
        </div>
        <a href="javascript:;" class="m-bottom" onclick="check_form1()">提交信息</a>
      <!-- 循环结束 -->
    </div>
    </form>
    <!------------------------ PC ------------------------>
    <form action="{:url('User/m_edit_member_info')}" method="post" id="form2">
    <div class="PC">
        <!-- 公共头部 -->
        {include file="public/p_header" /}
        <!-- 公共头部结束 -->
        <div class="pc-content">
            {include file="public/p_user" /}

            <div class="PC_right">
                {include file="public/p_user_info" /}
                <div class="pc-tihuan">
                    <div class="pc-tihuan-headline">
                        <div>
                            <p>
                                <span class="pc-zhong">
                                    <a href="{:url('User/my_center')}">修改个人信息</a>
                                </span>
                                <span>
                                    <a href="{:url('User/edit_password')}">修改密码</a>
                                </span>
                                <span>
                                    <a href="{:url('User/edit_mobile')}">更换手机号</a>
                                </span>
                            </p>
                        </div>
                    </div>
                    <div class="pc-tihuan-content">
                        <div>
                            <label for="image_file">
                                <img class="image_file" src="{if condition='empty($user.logo)'}__STATIC__/index/touxiang.png{else /}{$user.logo}{/if}" />
                                <span>修改个人头像</span>
                            </label>
                            <input type="hidden" class="image_file" name="image_file"/>
                            <input type="file" id="image_file" style="display:none;" onchange="uploadImg(this);" />
                        </div>
                        <div>
                            <span>手机号</span>
                            <span>{$user.mobile}</span>
                            <span>
                                <a href="{:url('User/edit_mobile')}">修改</a>
                            </span>
                            <span>仅自己可见</span>
                        </div>
                        <div>
                            <label for="pc-name">昵称</label>
                            <input type="text" id="pc-name" name="realname" value="{$user.realname}" onkeyup="set_realname(this)">
                        </div>
                        <div>
                            <span>性别</span>
                            <label for="pc-woman" class="pc-gender {if condition='$user.sex eq 0'}pc-gender-zhong{/if}">
                                <span>
                                </span>
                                <input type="radio" name="sex" id="pc-woman" {if condition="$user.sex eq 0"} checked {/if} value="0">
                                <span>女</span>
                            </label>
                            <label for="pc-men" class="pc-gender {if condition='$user.sex eq 1'}pc-gender-zhong{/if}">
                                <span>
                                </span>
                                <input type="radio" name="sex" id="pc-men" {if condition="$user.sex eq 1"} checked="checked" {/if} value="1">
                                <span>男</span>
                            </label>
                        </div>
                        <div>
                            <span>生日</span>
                            <span id="pc-riqi">
                            </span>
                        </div>
                        <div>
                            <a href="javascript:;" onclick="check_form2()">提交信息</a>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <!-- 公共脚部  -->
        {include file="public/p_footer" /}
        <!-- 公共脚部 结束 -->
    </div>
    </form>

    <script src="__STATIC__/index/js/a.js"></script>
    <script>
        function uploadImg(obj) {
            // 隐藏的文本框
            var grandmaster_input = obj.previousSibling.previousSibling;
            // 预览的image标签
            var grandmaster_img = obj.previousSibling.previousSibling.previousSibling.previousSibling.firstChild.nextElementSibling;
            // 当前选中的文件
            var image_file = obj.files[0];
            // 当前选中文件的种类
            var image_file_type = image_file.type;
            // 限制上传文件的类别
            var image_type_reg =
                /^(image\/bmp|image\/gif|image\/jpeg|image\/jpg|image\/png|image\/tiff)$/i;
            // 验证上传文件的类别
            if (image_type_reg.test(image_file_type) != true) {
                // 格式不对报错
//                alert("请上传正确格式,例如 : .bmp .gif .jpeg .jpg .png .tiff");
                layer.msg('请上传正确格式,例如 : .bmp .gif .jpeg .jpg .png .tiff',{icon:2,time:1500,shade: 0.1}, function(index){
                    layer.close(index);
                });
                return;
            }
            // 创建一个文件对象
            var file_reader = new FileReader();
            // 加载文件
            file_reader.onload = function (file) {
                // 计算文件大小
                var str = file.target.result;
                str = str.substring(str.indexOf(",") + 1);
                if (str.indexOf("=") > 0) {
                    str = str.substring(0, str.indexOf("="));
                }
                var str_length = str.length;
                var file_length = parseInt(str_length - (str_length / 8) * 2);
                // 文件不允许大于 1M
                if (file_length >= 1048576) {
//                    alert("文件不允许大于 1M ");
                    layer.msg('文件不允许大于 1M',{icon:2,time:1500,shade: 0.1}, function(index){
                        layer.close(index);
                    });
                    return false;
                }
                // 设置图片为选中文件

                grandmaster_img.src = file.target.result;
                grandmaster_input.value = file.target.result;
            };
            file_reader.readAsDataURL(image_file);
        };

        $(function () {
            $('.pc-gender').click(function () {
                $('.pc-gender').removeClass('pc-gender-zhong');
                $(this).addClass('pc-gender-zhong');

            });
            var options = {
                "dateFormat": "bigEndian",
                "wraper": "fieldset",
                "iegend": "生日选择"
            }
            $('#pc-riqi').birthdaypicker(options);
            var year = '{$user.birthday_year}';
            var month = '{$user.birthday_month}';
            var day = '{$user.birthday_day}';
            
            var numbers = $(".birth-year").find("option"); //获取select下拉框的所有值
            for (var j = 1; j < numbers.length; j++) {
                if ($(numbers[j]).val() == year) {
                    $(numbers[j]).attr("selected", "selected");
                }
            }
            var numbers1 = $(".birth-month").find("option"); //获取select下拉框的所有值
            for (var k = 1; k < numbers.length; k++) {
                if ($(numbers1[k]).val() == month) {
                    $(numbers1[k]).attr("selected", "selected");
                }
            }
            var numbers2 = $(".birth-day").find("option"); //获取select下拉框的所有值
            for (var l = 1; l < numbers.length; l++) {
                if ($(numbers2[l]).val() == day) {
                    $(numbers2[l]).attr("selected", "selected");
                }
            }
        });

        /**
         * 移动端修改信息
         * 移动端修改信息
         */
        function check_form1(){
            var logo = $('#form1').find('input[name=image_file]').val();     //会员头像
            var realname = $('#form1').find('input[name=realname]').val();
            var sex = $('#form1').find('#sex option:checked').val();
            var birthday = $('#form1').find('input[name=birthday]').val();

            $.post("{:url('User/m_edit_member_info')}",
                {logo:logo,realname:realname,sex:sex,birthday:birthday},
                function(data){
                    if(data.code == 1){
                        layer.msg('修改成功',{icon:1,time:1500,shade: 0.1}, function(index){
                            layer.close(index);
                            location.reload();
                        });
                    }else{
                        layer.msg(data.msg,{icon:1,time:1500,shade: 0.1}, function(index){
                            layer.close(index);
                        });
                    }
                }
            );
        }

        /**
         * 检查表单信息
         * PC端修改信息
         */
        function check_form2(){
            var logo = $('#form2').find('input[name=image_file]').val();     //会员头像
            var realname = $('#form2').find('input[name=realname]').val();
            var sex = $('#form2').find('input[name=sex]:checked').val();
            var birth_year = $('#form2').find('.birth-year option:selected').val();
            var birth_month = $('#form2').find('.birth-month option:selected').val();
            var birth_day = $('#form2').find('.birth-day option:selected').val();

            $.post("{:url('User/my_center')}",
                {logo:logo,realname:realname,sex:sex,birth_year:birth_year,birth_month:birth_month,birth_day:birth_day},
                function(data){
                    if(data.code == 1){
                        layer.msg('修改成功',{icon:1,time:1500,shade: 0.1}, function(index){
                            layer.close(index);
                            location.reload();
                        });
                    }else{
                        layer.msg(data.msg,{icon:1,time:1500,shade: 0.1}, function(index){
                            layer.close(index);
                        });
                    }
                }
            );
        }



        /**
         * 返回上一页
         */
        function go_back(){
            window.history.back();  //返回上一页

        }

        /**
         * 设置会员昵称
         */
        function set_realname(obj){
            var value = $(obj).val();
            $('input[name=realname]').val(value);
        }

        /**
         * 完善会员信息
         */
        function edit_member_info(){
            window.location.href = "{:url('User/my_center')}";
        }


    </script>
</body>

</html>